import Vue from 'vue'
import VueRouter from 'vue-router'
// import Login from '../views/Login.vue'
// import Home from '../views/Home.vue'
// import Welcome from '../components/Welcome.vue'
// import Admin from '../components/admin/Admin.vue'
// import User from '../components/user/User.vue'
// import Company from '../components/company/Company.vue'
// import Add from '../components/company/Add.vue'
// import Position from '../components/company/Position.vue'
// import Addposition from '../components/company/Addposition.vue'
// import Pagemanage from '../components/pagemanage/Pagemanage.vue'
// import All from '../components/company/All.vue'

const Login = () => import(/* webpackChunkName:"login_home_welcome" */ '../views/Login.vue')
const Home = () => import(/* webpackChunkName:"login_home_welcome" */ '../views/Home.vue')
const Welcome = () => import(/* webpackChunkName:"login_home_welcome" */ '../components/Welcome.vue')

const Admin = () => import(/* webpackChunkName:"admin" */ '../components/admin/Admin.vue')
const Password = ()=>import(/* webpackChunkName:"admin" */ '../components/admin/Password.vue')

const Add = () => import(/* webpackChunkName:"commpany" */ '../components/company/Add.vue')
const Addposition = () => import(/* webpackChunkName:"commpany" */ '../components/company/Addposition.vue')
const All = () => import(/* webpackChunkName:"commpany" */ '../components/company/All.vue')
const Company = () => import(/* webpackChunkName:"commpany" */ '../components/company/Company.vue')
const Position = () => import(/* webpackChunkName:"commpany" */ '../components/company/Position.vue')

const Pagemanage = () => import(/* webpackChunkName:"pagemanage" */ '../components/pagemanage/Pagemanage.vue')

const User = () => import(/* webpackChunkName:"user" */ '../components/user/User.vue')

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/login' },
  { path: '/login', component: Login },
  {
    path: '/home', component: Home, redirect: '/company', children: [
      { path: '/welcome', component: Welcome },
      { path: '/admin', component: Admin },
      { path: '/user', component: User },
      { path: '/company', component: Company },
      { path: '/company/add', component: Add },
      { path: '/position', component: Position },
      { path: '/position/add', component: Addposition },
      { path: '/pagemanage', component: Pagemanage },
      { path: '/all', component: All },
      { path: '/password', component: Password }
    ]
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if (to.path == "/login") return next();
  const tokenStr = window.sessionStorage.getItem("token");
  if (!tokenStr) return next("/login");
  next();
});

export default router
